<!--
 * @version: 
 * @Author: yu
 * @Date: 2023-06-28 14:48:22
 * @LastEditors: Andy
 * @LastEditTime: 2023-06-28 22:29:49
-->
<template>
    <div>
        <el-table :data="tableData" style="width: 100%;margin-bottom: 20px;" row-key="id" border
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
            <el-table-column prop="id" label="用户编号" sortable width="180"></el-table-column>
            <el-table-column prop="username" label="用户名" width="180"></el-table-column>
            <el-table-column prop="rolename" label="所属角色"></el-table-column>

            <el-table-column prop="status" label="状态">
                <template v-slot="item">
                    <el-button v-if="item.row.status === 1" type="primary" size="small">启用</el-button>
                    <el-button v-else type="danger" size="small">禁用</el-button>
                </template>
            </el-table-column>

            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button @click="edit(scope.row.uid)" type="primary" size="small">编辑</el-button>
                    <el-button @click="del(scope.row.uid)" type="danger" size="small">删除</el-button>
                </template>
            </el-table-column>

        </el-table>
        <!-- page-size每页显示条目个数，支持 .sync 修饰符  currentPage 改变时会触发  分页-->
        <el-pagination @current-change="curlPage" :page-size="size" background layout="prev, pager, next" :total="total">
        </el-pagination>
    </div>
</template> 
<script>
import { mapActions, mapGetters } from 'vuex'
import { userDel } from '@/request/api'
import { successAlert } from '@/utils/alert'
export default {
    data() {
        return {

        }
    },
    methods: {
        ...mapActions({
            requestMember: 'member/listActions',  //发起管理员列表请求
            requestCount: 'member/countActions',  //发起管理员总数请求
            requestPage: 'member/pageActions'
        }),
        //编辑
        edit(uid) {
            this.$emit('edit',uid)
        },
        //获取当前页码数
        curlPage(page) {
            this.requestPage(page)
            // console.log(page);
            this.requestMember()
        },
        //删除
        del(uid) {
            // console.log(id);
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                userDel({ uid }).then(res => {
                    // console.log(res);
                    if (res.code === 200) {
                        //提示信息
                        successAlert(res.msg)
                        //更新管理员列表
                        this.requestMember()
                        //更新总记录数
                        this.requestCount()
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }
    },
    mounted() {
        //发起管理员列表请求
        this.requestMember()
        //发起管理员总数请求
        this.requestCount()
    },
    watch: {},
    computed: {
        ...mapGetters({
            tableData: 'member/list',
            total: 'member/total',
            size: 'member/size'
        })
    },
    filters: {},
    components: {}
}
</script>
<style scoped>
.el-pagination {
    float: right;
}
</style>